//
//  LssUserAccount.swift
//  freeChatting
//
//  Created by mac on 16/4/19.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class LssUserAccount: NSObject,NSCoding{
    //用户授权的唯一票据，用于调用微博的开放接口
    var access_token:String?
    //access_token的生命周期，单位是秒数
    var expires_in:Int = 0{
        didSet{
        expires_date = NSDate().dateByAddingTimeInterval(Double(expires_in))
        }
    }
    //授权用户的UID
    var uid:String?
    //用户头像地址（大图），180×180像素
    var avatar_large:String?
    //用户昵称
    var screen_name:String?
    //将过期时间转换为date
    var expires_date:NSDate?
    //kvc构造函数
    init(dict: [String:AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    //MARK:- 归档

    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(expires_date, forKey: "expires_date")
    }
    //MARK:- 解档
    
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large")as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name")as? String
        expires_date = aDecoder.decodeObjectForKey("expires_date")as? NSDate
    }
    

}
//extension LssUserAccount{
//    func encodeWithCoder(aCoder: NSCoder) {
//        aCoder.encodeObject(access_token, forKey: "access_token")
//        aCoder.encodeObject(uid, forKey: "uid")
//        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
//        aCoder.encodeObject(screen_name, forKey: "screen_name")
//        aCoder.encodeObject(expires_date, forKey: "expires_date")
//    }
//     init?(coder aDecoder: NSCoder) {
//        
//    }
//
//}
